<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        #div1 {
            width: 850px;
            height: 500px;
            margin: 50px auto;
            overflow: hidden;
            position: relative;
        }

        #div1 ul {
            position: absolute;
            left: 0;
            top: 0;
        }

        #div1 ul li {
            height: 500px;
            display: block;
        }

        #div1 ol {
            position: absolute;
            right: 10%;
            bottom: 10px;
            z-index: 6
        }

        #div1 ol li {
            width: 20px;
            height: 20px;
            background: #fff;
            margin-left: 5px;
            float: left;
            line-height: 20px;
            text-align: center;
            border-radius: 50%;
        }

        #div1 ol li.ac {
            background: red;
            color: #fff;
        }

        #div1>a {
            text-decoration: none;
            position: absolute;
            top: 50%;
            margin-top: -10px;
            height: 40px;
            line-height: 32px;
            text-align: center;
            width: 40px;
            font-size: 40px;
            vertical-align: middle;
            color: #fff;
            background: rgba(0, 0, 0, 0.5);
            z-index: 6;
            border-radius: 5px;
        }

        #goPrev {
            left: 0;
        }

        #goNext {
            right: 0;
        }

        img {
            width: 850px;
            height: 500px;
        }
    </style>

</head>
<body>
    <div id="div1">
            <ul>
                <li><img src="images/1.jpg" /></li>
                <li><img src="images/2.jpg" /></li>
                <li><img src="images/3.jpg" /></li>
                <li><img src="images/4.jpg" /></li>
                <li><img src="images/5.jpg" /></li>
            </ul>
            <ol>

            </ol>
            <a href="javascript:;" id="goPrev">&laquo;</a>
            <a href="javascript:;" id="goNext">&raquo;</a>
        </div>
        <!-- <script>
            var div = document.querySelector('#div1'),
                ul = div.querySelector('ul'),
                list = ul.querySelectorAll('li'),
                ol = div.querySelector('ol'),
                goPrev = document.querySelector('#goPrev'),
                goNext = document.querySelector('#goNext'),
                btns = []
            var timer = null
            var isMove = false
            var index = 0
            var lastIndex = 0
            var len = list.length
            var height = list[0].offsetHeight
    
            ul.appendChild(list[0].cloneNode(true))
            ul.style.height = (len + 1) * top + 'px'
            for (let i = 0; i < len; i++) {
                let li = document.createElement('li')
                li.innerHTML = i + 1
                if (i === 0) li.className = 'ac'
                ol.appendChild(li)
                btns.push(li)
                li.onclick = function () {
                    if (!isMove) {
                        isMove = true
                        lastIndex = index
                        index = i
                        btns[lastIndex].classList.remove('ac')
                        btns[index].classList.add('ac')
                        move(index)
                    }
                }
            }
            goNext.onclick = function () {
                if (!isMove) {
                    isMove = true
                    lastIndex = index
                    index++
                    if (index === len) {
                        index = 0
                        move(len, function () {
                            ul.style.top = '0px'
                        })
                    } else {
                        move(index)
                    }
                    btns[lastIndex].classList.remove('ac')
                    btns[index].classList.add('ac')
    
                }
    
            }
            goPrev.onclick = function () {
                if (!isMove) {
                    isMove = true
                    lastIndex = index
                    index--
                    if (index < 0) {
                        index = len - 1
                        ul.style.top = -len * height + 'px'
                    }
                    btns[lastIndex].classList.remove('ac')
                    btns[index].classList.add('ac')
                    move(index)
                }
            }
    
            function keyerON() {
                timer = setInterval(() => {
                    goNext.onclick()
                }, 2000)
            }
            keyerON()
            div.onmouseenter = function () {
                clearInterval(timer)
            }
            div.onmouseleave = keyerON
            function move(num, fn) {
                var start = ul.offsetTop
                var end = -num * height
                div.timer = setInterval(() => {
                    var distance = end - start
                    var speed = distance > 0 ? Math.ceil(distance / 10) : Math.floor(distance / 10);
                    start += speed
                    ul.style.top = start + 'px'
                    if (start === end) {
                        clearInterval(div.timer)
                        isMove = false
                        fn && fn()
                    }
                }, 30)
    
    
            }
        </script> -->
</body>
</html>
<script>
    class  fn {
        constructor (){
            this.div = document.querySelector('#div1')
            this.ul = this.div.querySelector('ul')
            this.list = this.ul.querySelectorAll('li')
            this.ol = this.div.querySelector('ol')
            this.goPrev = document.querySelector('#goPrev')
            this.goNext = document.querySelector('#goNext')
            this.btns = []
            this.timer = null
            this.isMove = false
            this.index = 0
            this.lastIndex = 0
            this.len = this.list.length
            this.height = this.list[0].offsetHeight
            this.ulClone()
            this.goPrevOn()
            this.goNextOn()
            this.setFn()
            this.enterFn()
            this.leaveFn()
        }
        ulClone() {

           this.ul.appendChild(this.list[0].cloneNode(true))
           this.ul.style.height = (this.len + 1) * this.height + 'px'
            this. olChildenPush()
        }
        olChildenPush(){
            const that = this
            for (let i = 0; i < that.len; i++) {
                let li = document.createElement('li')
                li.innerHTML = i + 1
                if (i === 0) li.className = 'ac'
                that.ol.appendChild(li)
                that. btns.push(li)
                li.onclick = function () {
                    if (!that.isMove) {
                       that.isMove = true
                        that.lastIndex = that.index
                        that.index = i
                        that.btns[that.lastIndex].classList.remove('ac')
                        that.btns[that.index].classList.add('ac')
                        that.moveFn(that.index)
                    }
                }
               
            }
        }
        

        
        goNextOn(){
            const that = this
           this.goNext.onclick =  function() {
                
                if (!that.isMove) {
                    that.isMove = true
                    that.lastIndex = that.index
                    that.index++
                    if (that.index === that.len) {
                        that.index = 0
                        that.moveFn(that.len, function () {
                            that.ul.style.top = '0px'
                        })
                    } else {
                        that.moveFn(that.index)
                    }
                    that.btns[that.lastIndex].classList.remove('ac')
                    that.btns[that.index].classList.add('ac')
    
                }
    
            }

        }
        goPrevOn(){
            const that = this
           this.goPrev.onclick = function () {
                if (!that.isMove) {
                     that.isMove = true
                    that.lastIndex = that.index
                    that.index--
                    if (that.index < 0) {
                        that.index = that.len - 1
                        that.ul.style.top = -that.len * that.height + 'px'
                    }
                    that.btns[that.lastIndex].classList.remove('ac')
                    that.btns[that.index].classList.add('ac')
                    that.moveFn(that.index)
                }
            }

        }
        setFn(){
               this.timer= setInterval(() => {
                this.goNext.onclick()
                }, 2000)
              
      }
      enterFn(){
        this.div.onmouseenter =  () => {
                clearInterval(this.timer)
            }
      }
      leaveFn(){
          this.div.onmouseleave = ()=>{

            this.timer = setInterval(() => {
                this. goNext.onclick()
                }, 2000)  
          }
          }
           moveFn(num, fn) {
                var start = this.ul.offsetTop
                var end = -num * this.height
               
                this.div.timer = setInterval(() => {
                    var distance = end - start
                    var speed = distance > 0 ? Math.ceil(distance / 10) : Math.floor(distance / 10);
                    start += speed
                   this.ul.style.top = start + 'px'
                    if (start === end) {
                        clearInterval(this.div.timer)
                        this.isMove = false
                        fn && fn()
                    }
                }, 30)
    
    
            }
    }
     
      
        
   




new fn ()
</script>